import 'package:json_annotation/json_annotation.dart';


part 'moment_model.g.dart';

@JsonSerializable()
class MomentModel {
  @JsonKey(name: "momentId")
  int momentId;
  @JsonKey(name: "creatorInfo")
  CreatorInfo creatorInfo;
  @JsonKey(name: "title")
  String title;
  @JsonKey(name: "content")
  String content;
  @JsonKey(name: "topics")
  dynamic topics;
  @JsonKey(name: "multiMedia")
  List<MultiMedia> multiMedia;
  @JsonKey(name: "publishTime")
  dynamic publishTime;
  @JsonKey(name: "likeCnt")
  dynamic likeCnt;
  @JsonKey(name: "collectCnt")
  int collectCnt;
  @JsonKey(name: "commentsCnt")
  int commentsCnt;
  @JsonKey(name: "userPosition")
  String? userPosition;

  MomentModel({
    required this.momentId,
    required this.creatorInfo,
    required this.title,
    required this.content,
    required this.topics,
    required this.multiMedia,
    required this.publishTime,
    required this.likeCnt,
    required this.collectCnt,
    required this.commentsCnt,
    this.userPosition,
  });

  MomentModel copyWith({
    int? momentId,
    CreatorInfo? creatorInfo,
    String? title,
    String? content,
    dynamic topics,
    List<MultiMedia>? multiMedia,
    dynamic publishTime,
    dynamic likeCnt,
    int? collectCnt,
    int? commentsCnt,
    dynamic userPosition,
    CommentList? commentList,
  }) =>
      MomentModel(
        momentId: momentId ?? this.momentId,
        creatorInfo: creatorInfo ?? this.creatorInfo,
        title: title ?? this.title,
        content: content ?? this.content,
        topics: topics ?? this.topics,
        multiMedia: multiMedia ?? this.multiMedia,
        publishTime: publishTime ?? this.publishTime,
        likeCnt: likeCnt ?? this.likeCnt,
        collectCnt: collectCnt ?? this.collectCnt,
        commentsCnt: commentsCnt ?? this.commentsCnt,
        userPosition: userPosition ?? this.userPosition,
      );

  factory MomentModel.fromJson(Map<String, dynamic> json) => _$MomentModelFromJson(json);

  Map<String, dynamic> toJson() => _$MomentModelToJson(this);
}

@JsonSerializable()
class CommentList {
  @JsonKey(name: "commentItemDtos")
  dynamic commentItemDtos;

  CommentList({
    required this.commentItemDtos,
  });

  CommentList copyWith({
    dynamic commentItemDtos,
  }) =>
      CommentList(
        commentItemDtos: commentItemDtos ?? this.commentItemDtos,
      );

  factory CommentList.fromJson(Map<String, dynamic> json) => _$CommentListFromJson(json);

  Map<String, dynamic> toJson() => _$CommentListToJson(this);
}

@JsonSerializable()
class CreatorInfo {
  @JsonKey(name: "userId")
  int userId;
  @JsonKey(name: "avatar")
  String avatar;
  @JsonKey(name: "userName")
  String userName;

  CreatorInfo({
    required this.userId,
    required this.avatar,
    required this.userName,
  });

  CreatorInfo copyWith({
    int? userId,
    String? avatar,
    String? username,
  }) =>
      CreatorInfo(
        userId: userId ?? this.userId,
        avatar: avatar ?? this.avatar,
        userName: username ?? this.userName,
      );

  factory CreatorInfo.fromJson(Map<String, dynamic> json) => _$CreatorInfoFromJson(json);

  Map<String, dynamic> toJson() => _$CreatorInfoToJson(this);
}

@JsonSerializable()
class MultiMedia {
  @JsonKey(name: "name")
  String name;
  @JsonKey(name: "type")
  String type;
  @JsonKey(name: "url")
  String url;
  @JsonKey(name: "width")
  int width;
  @JsonKey(name: "height")
  int height;
  @JsonKey(name: "size")
  int size;
  @JsonKey(name: "cover")
  bool cover;

  MultiMedia({
    required this.name,
    required this.type,
    required this.url,
    required this.width,
    required this.height,
    required this.size,
    required this.cover,
  });

  MultiMedia copyWith({
    String? name,
    String? type,
    String? url,
    int? width,
    int? height,
    int? size,
    bool? cover,
  }) =>
      MultiMedia(
        name: name ?? this.name,
        type: type ?? this.type,
        url: url ?? this.url,
        width: width ?? this.width,
        height: height ?? this.height,
        size: size ?? this.size,
        cover: cover ?? this.cover,
      );

  factory MultiMedia.fromJson(Map<String, dynamic> json) => _$MultiMediaFromJson(json);

  Map<String, dynamic> toJson() => _$MultiMediaToJson(this);
}
